<?php
/**
 * 博主信息控件 bloggerinfocontroller.php
 * 参数简介：
 * bloggerId 博主ID 即用户ID
 * blogId 博客ID
 * type 类型  1表示根据bloggerId获取博主信息 2表示根据blogId获取博主信息
 * isGetBlog 0 表示不获取 1 表示获取最新博文 2表示获取最热博文
 * limit isGetBlog 不为0 获取博文条数
 * fromWhere 1 来自于博主博文列表 2 来自于博文详情页
 * Create on 2015-09-11
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\channel\blog;


class BloggerInfoController extends \haibao\cms\business\control\pc\channel\blog\BlogController{
	
	const BLOGGER_INFO_BY_USER_ID = 1;
	const BLOGGER_INFO_BY_BLOG_ID = 2;
	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	/**
	 * 获取模版内容
	 * @param : String $content
	 */
	public function displayTemplateHtml(){
	
		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		$bloggerInfo = array();
		$bloggerId = $fromWhere = 0;
		if($controlData['manual']){	
			$type = isset($controlData['manual']['type'])?$controlData['manual']['type']:self::BLOGGER_INFO_BY_USER_ID;
			if($type == self::BLOGGER_INFO_BY_USER_ID){

				$bloggerId = $controlData['manual']['bloggerId'];
				$bloggerInfo = $this->getBloggerInfoById($bloggerId);
			
			}elseif($type == self::BLOGGER_INFO_BY_BLOG_ID){
				
				$blogInfo = $this->getBlogInfoByBlogId($controlData['manual']['blogId']);
				if($blogInfo){
					$bloggerId = $blogInfo['uid'];
					$bloggerInfo = $this->getBloggerInfoById($bloggerId);
				}
			}
			
			if($bloggerInfo && $controlData['manual']['isGetBlog']){
				$fromWhere = $controlData['manual']['fromWhere'];
				$this->getBloggerBlogList($controlData['manual'],$bloggerId);
			}
		}

		$this->assign('bloggerInfo', $bloggerInfo);
		$this->assign('fromWhere', $fromWhere);
		$this->assign('bbsHost', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BBS));
		$this->assign('fashionistaHost', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU));
		$path = $this->generateHtmlPath(__CLASS__);
		$this->generateHtml($path,$content);
		$content = $this->getHtml($path);
		return $content;
	}
	
	
	/**
	 * 获取博主博文
	 */
	private function getBloggerBlogList($dataCondition,$bloggerId){
		
		if($dataCondition['isGetBlog'] == 1){
			$orderBy = \haibao\cms\data\control\BlogController::ORDER_BY_DATE;
		}else{
			$orderBy = \haibao\cms\data\control\BlogController::ORDER_BY_VIRE;
		}
		$limit = $dataCondition['limit']?$dataCondition['limit']:5;
		$blogList = $this->getBlogListByUserIds($bloggerId,$limit,$orderBy);
		$this->assign('blogList',$blogList);
	}
}